var maxSubArray = function(nums) {
    let lenOfArr = nums.length;
    if (!lenOfArr) return lenOfArr;
    let cur = 0;
    let max = Number.MIN_SAFE_INTEGER;
    for (let i = 0; i < lenOfArr; i++) {
        cur += nums[i];
        max = Math.max(max, cur);
        cur = cur < 0 ? 0 : cur;
    }
    return max;
};



let nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
console.log(maxSubArray(nums))